package com.liu.dw.config;

import io.swagger.annotations.ApiModel;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 接口响应状态码
 */
@ApiModel("HTTP状态码")
@Getter
public enum ResponseStatus {

    /**
     * 操作成功
     */
    OK("200", "OK"),
    LOGIN_NO("902","用户没有登录"),
    ERR_AUTH_FAILURE("900","认证错误。"),
    ERR_OBJECT_NOT_AVAILABLE("901","服务不可用（服务被禁用）"),
    ERR_PERM_DENIED("1000","权限拒绝。"),
    ERR_INVALID_ARGS("1001","参数错误"),
    ERR_SYSTEM("1002","系统错误"),
    ERR_RESOURCE_NOT_FOUND("1003","资源不存在"),
    ERR_OBJECT_NOT_FOUND("1004","对象不存在"),
    ERR_OBJECT_EXISTS_ALREADY("1005","对象已存在"),
    ;
    /**
     * 状态值
     */
    private final String value;
    /**
     * 文字说明
     */
    private final String reason;

    ResponseStatus(String value, String reason) {
        this.value = value;
        this.reason = reason;
    }

    public String value() {
        return this.value;
    }

    public String reason() {
        return this.reason;
    }

    public static void main(String[] args) {
        //用于校验错误码是否重复
        Map<String, ResponseStatus> codeMap = new HashMap<>();
        for (ResponseStatus value : ResponseStatus.values()) {
            if (codeMap.containsKey(value.value())) {
                throw new IllegalArgumentException(codeMap.get(value.value()) + "和" + value + " 重复了");
            } else {
                codeMap.put(value.value(), value);
            }
        }
    }
}
